package com.gundam.tools.lint.checks

import com.android.tools.lint.detector.api.*
import com.intellij.psi.PsiMethod
import org.jetbrains.uast.UCallExpression

/**
 * GlideApp 检查
 */
@Suppress("UnstableApiUsage")
class GlideAppDetector : Detector(), Detector.UastScanner {
    companion object {
        @JvmField
        val ISSUE = Issue.create(
                // ID: used in @SuppressLint warnings etc
                "GlideApp",

                // Title -- shown in the IDE's preference dialog, as category headers in the
                // Analysis results window, etc
                "避免使用Glide",

                // Full explanation of the issue; you can use some markdown markup such as
                // `monospace`, *italic*, and **bold**.
                "请使用工具类**GlideApp**，内存已经做过优化处理",
                Category.USABILITY,
                7,
                Severity.WARNING,
                Implementation(
                        GlideAppDetector::class.java,
                        Scope.JAVA_FILE_SCOPE))
    }

    override fun getApplicableMethodNames(): List<String>? {
        return listOf("with")
    }

    override fun visitMethodCall(context: JavaContext, node: UCallExpression, method: PsiMethod) {
        if (context.evaluator.isMemberInClass(method, "com.bumptech.glide.Glide")) {
            context.report(ISSUE, node, context.getLocation(node), "请勿直接调用com.bumptech.glide.Glide，应该使用统一工具类GlideApp")
        }
    }
}